package chapter02.d02;
/*
 * synchronized起作用
 * 
 */

public class Demo3 {
	public static void main(String[] args) {
		Test3 t = new Test3();
		for (int i = 0; i < 3; i++) {
			Thread thread = new MyThread3(t);
			thread.start();
		}
	}

}

class Test3 {
	public void test() {
		synchronized (this) {
			System.out.println("test开始..");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("test结束..");
		}

	}
}

class MyThread3 extends Thread {
	
	private Test3 t;
	public MyThread3(Test3 t) {
		this.t = t;
	}

	public void run() {
		t.test();
	}
}
